Skip to content

fix(cloudflare/workers): send _redirects/_headers contents to Cloudflare - #928

Merged
sam-goodwin merged 1 commit into
mainfrom
claude/issue-927-fix-test-478c46
Jul 23, 2026
Merged

sam-goodwin merged 1 commit into
mainfrom
claude/issue-927-fix-test-478c46

Conversation

@sam-goodwin

Copy link
Copy Markdown
Member

Fixes #927.

readAssets read _redirects / _headers from the assets directory, excluded them from the upload manifest, and folded their contents into the change-detection hash — but never sent them to Cloudflare, so redirect/header rules were silently dropped (requests 404'd or fell through to the worker).

The distilled PutScriptRequest.metadata.assets.config type already carries headers / redirects (wire-encoded as _headers / _redirects), so no SDK change was needed — only the wiring:

  • readAssets now folds the file contents into the returned config, mirroring wrangler's metadata.assets.config._redirects / _headers. Explicit headers / redirects props still win. The merge happens after hashing, so existing asset hashes are unchanged (no spurious redeploys).
// Assets.ts
return {
  directory,
  config: mergeAssetsConfigFiles(config, { _headers, _redirects }),
  ...
};
  • The prebuilt-hash keep-assets path (prebuiltAssets.skip) never walks the directory, but the PUT replaces the asset config wholesale — it now re-reads just the two files so a no-op deploy doesn't wipe the rules:
metadataAssets = {
  config: mergeAssetsConfigFiles(
    prebuiltAssets.config,
    yield* readAssetsConfigFiles(prebuiltAssets.directory),
  ),
};
  • Dev parity: LocalWorkerProvider reads the same files and passes their contents to the local runtime, which already parses headers / redirects strings.

Live test (test/Cloudflare/Workers/AssetsConfigFiles.test.ts) deploys a worker with a _redirects + _headers fixture and asserts over HTTP: the 301 applies, the header applies, _redirects itself isn't served, editing _redirects deploys the new rules, and the rules survive a keep-assets (hash-match skip) deploy.

🤖 Generated with Claude Code

The special asset files were read from the assets directory, excluded
from the upload manifest, and folded into the change-detection hash —
but their contents were never sent in the script metadata, so redirect
and header rules silently never applied.

- readAssets now folds the file contents into the returned config
  (metadata.assets.config._redirects/_headers, matching wrangler)
- the prebuilt-hash keep-assets path re-reads just the two files so a
  no-op deploy doesn't wipe the rules
- local dev passes the file contents to the runtime for parity

Fixes #927

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@alchemy-version-bot

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/6005f3f

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/6005f3f

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/6005f3f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

# _redirects / _headers are read and hashed, but never sent to Cloudflare

1 participant